/*
* test1
*/
package com.pitop.market.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.market.entity.MarketRepairRecord;
import com.pitop.market.service.MarketRepairRecordSV;

/**
 * 维修记录 控制器
 *
 * @author test1
 */
@RestController
@RequestMapping("/marketRepairRecord")
@Slf4j
@Api(value = "维修记录控制器", description = "维修记录控制器")
public class MarketRepairRecordCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private MarketRepairRecordSV marketRepairRecordSV;

    /**
     * 查询MarketRepairRecord一个详情信息
     *
     * @param id
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询MarketRepairRecord一个详情信息", notes = "查询MarketRepairRecord一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public MarketRepairRecord load(Long id, String code) {
        if (id == null) {
            return null;
        }
        if (code == null) {
            return null;
        }
        MarketRepairRecord marketRepairRecord = marketRepairRecordSV.load(id, code);
        log.info(JSON.toJSONString(marketRepairRecord));
        return marketRepairRecord;
    }


    /**
     * 根据条件id查询MarketRepairRecord一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询MarketRepairRecord一个详情信息", notes = "查询MarketRepairRecord一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public MarketRepairRecord loadById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        MarketRepairRecord marketRepairRecord = marketRepairRecordSV.loadById(id);
        log.info(JSON.toJSONString(marketRepairRecord));
        return marketRepairRecord;
    }

    /**
     * 根据条件code查询MarketRepairRecord一个详情信息
     *
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询MarketRepairRecord一个详情信息", notes = "查询MarketRepairRecord一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public MarketRepairRecord loadByCode(@PathVariable String code) {
        if (code == null) {
            return null;
        }
        MarketRepairRecord marketRepairRecord = marketRepairRecordSV.loadByCode(code);
        log.info(JSON.toJSONString(marketRepairRecord));
        return marketRepairRecord;
    }


    /**
     * 查询MarketRepairRecord信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询MarketRepairRecord信息集合", notes = "查询MarketRepairRecord信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "createTimeBegin", value = "维修时间", paramType = "query"),
            @ApiImplicitParam(name = "createTimeEnd", value = "维修时间", paramType = "query")
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<MarketRepairRecord> list(@RequestBody @ApiIgnore MarketRepairRecord marketRepairRecord, Integer curPage, Integer pageSize) {
        Page<MarketRepairRecord> page = new Page<MarketRepairRecord>(pageSize, curPage);
        List<MarketRepairRecord> marketRepairRecords = marketRepairRecordSV.list(marketRepairRecord, page.genRowStart(), page.getPageSize());
        int total = marketRepairRecordSV.count(marketRepairRecord);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return marketRepairRecords;
    }


    /**
     * 查询MarketRepairRecord信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询MarketRepairRecord信息集合", notes = "查询MarketRepairRecord信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<MarketRepairRecord> listByPk(Long id, String code, Integer curPage, Integer pageSize) {
        Page<MarketRepairRecord> page = new Page<MarketRepairRecord>(pageSize, curPage);
        List<MarketRepairRecord> marketRepairRecords = marketRepairRecordSV.list(id, code, page.genRowStart(), page.getPageSize());
        int total = marketRepairRecordSV.count(id, code);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return marketRepairRecords;
    }

    /**
     * 统计MarketRepairRecord信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计MarketRepairRecord信息数量根据主键", notes = " 统计MarketRepairRecord信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(Long id, String code) {
        return marketRepairRecordSV.count(id, code);
    }

    /**
     * 统计MarketRepairRecord信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计MarketRepairRecord信息数量", notes = "统计MarketRepairRecord信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "deviceCode", value = "设备编码", paramType = "query"),
            @ApiImplicitParam(name = "sn", value = "sn 码 设备SN码", paramType = "query"),
            @ApiImplicitParam(name = "repairAccountCode", value = "账户编码", paramType = "query"),
            @ApiImplicitParam(name = "errorTypeCode", value = "错误类型编码", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态 更换配件修复replace_parts，需要返厂故障Return_factory，无法修复故障broken，一般故障修复general_fault", paramType = "query"),
            @ApiImplicitParam(name = "feedback", value = "反馈信息 256英文字符", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "维修时间", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody MarketRepairRecord marketRepairRecord) {
        return marketRepairRecordSV.count(marketRepairRecord);
    }


    /**
     * 创建MarketRepairRecord
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建MarketRepairRecord", notes = "创建MarketRepairRecord")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceCode", value = "设备编码", paramType = "query"),
            @ApiImplicitParam(name = "sn", value = "sn 码 设备SN码", paramType = "query"),
            @ApiImplicitParam(name = "repairAccountCode", value = "账户编码", paramType = "query"),
            @ApiImplicitParam(name = "errorTypeCode", value = "错误类型编码", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态 更换配件修复replace_parts，需要返厂故障Return_factory，无法修复故障broken，一般故障修复general_fault", paramType = "query"),
            @ApiImplicitParam(name = "feedback", value = "反馈信息 256英文字符", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "维修时间", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public MarketRepairRecord build(@RequestBody @ApiIgnore MarketRepairRecord marketRepairRecord) {
        marketRepairRecordSV.save(marketRepairRecord);
        return marketRepairRecord;
    }


    /**
     * 修改MarketRepairRecord
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改MarketRepairRecord", notes = "修改MarketRepairRecord")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "deviceCode", value = "设备编码", paramType = "query"),
            @ApiImplicitParam(name = "sn", value = "sn 码 设备SN码", paramType = "query"),
            @ApiImplicitParam(name = "repairAccountCode", value = "账户编码", paramType = "query"),
            @ApiImplicitParam(name = "errorTypeCode", value = "错误类型编码", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态 更换配件修复replace_parts，需要返厂故障Return_factory，无法修复故障broken，一般故障修复general_fault", paramType = "query"),
            @ApiImplicitParam(name = "feedback", value = "反馈信息 256英文字符", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "维修时间", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public MarketRepairRecord modify(@RequestBody @ApiIgnore MarketRepairRecord marketRepairRecord) {
        marketRepairRecordSV.modify(marketRepairRecord);
        return marketRepairRecord;
    }

    /**
     * 删除MarketRepairRecord
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除MarketRepairRecord", notes = "删除MarketRepairRecord")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(Long id, String code) {
        marketRepairRecordSV.delete(id, code);
        return BeanRet.create(true, "删除MarketRepairRecord成功");
    }

}
